<template>
  <div>
    <div class="detail d-flex">
      <div class="flex-1">
        <p>{{ constellation.all }}</p>
        <p>综合指数</p>
      </div>
      <div class="flex-1">
        <p>{{ constellation.QFriend }}</p>
        <p>速配星座</p>
      </div>
      <div class="flex-1">
        <p>{{ constellation.color }}</p>
        <p>幸运颜色</p>
      </div>
      <div class="flex-1">
        <p>{{ constellation.number }}</p>
        <p>幸运数字</p>
      </div>
    </div>
    <div class="detailInfo">
      <section>
        <div class="title d-flex space-center middle">
          <div class="line"></div>
          <h4>综合运势</h4>
          <div class="line"></div>
        </div>
        <div class="rate d-flex space-center">
          <van-rate :value="content.rateAll" allow-half readonly color="#ffa92d" size="18"></van-rate>
        </div>
        <p>{{ content.summary }}</p>
      </section>
      <section>
        <div class="title d-flex space-center middle">
          <div class="line"></div>
          <h4>事业运势</h4>
          <div class="line"></div>
        </div>
        <div class="rate d-flex space-center">
          <van-rate :value="content.work" allow-half readonly color="#ffa92d" size="18"></van-rate>
        </div>
      </section>
      <section>
        <div class="title d-flex space-center middle">
          <div class="line"></div>
          <h4>爱情运势</h4>
          <div class="line"></div>
        </div>
        <div class="rate d-flex space-center">
          <van-rate :value="content.love" allow-half readonly color="#ffa92d" size="18"></van-rate>
        </div>
      </section>
      <section>
        <div class="title d-flex space-center middle">
          <div class="line"></div>
          <h4>财富运势</h4>
          <div class="line"></div>
        </div>
        <div class="rate d-flex space-center">
          <van-rate :value="content.money" allow-half readonly color="#ffa92d" size="18"></van-rate>
        </div>
      </section>
      <section>
        <div class="title d-flex space-center middle">
          <div class="line"></div>
          <h4>健康运势</h4>
          <div class="line"></div>
        </div>
        <div class="rate d-flex space-center">
          <van-rate :value="content.health" allow-half readonly color="#ffa92d" size="18"></van-rate>
        </div>
      </section>
    </div>
  </div>
</template>
<script>
export default {
  props: {
    constellation: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      content: {}
    }
  },
  watch: {
    constellation: {
      handler(val) {
        this.content = { ...val }
        this.filterData(this.content)
      },
      deep: true
    }
  },
  methods: {
    // 过滤数据
    filterData(val) {
      var all = val.all.replace('%', '')
      this.$set(this.content, 'rateAll', String(5 * (all / 100)))
      var health = val.health.replace('%', '')
      val.health = String(5 * (health / 100))
      var love = val.love.replace('%', '')
      val.love = String(5 * (love / 100))
      var work = val.work.replace('%', '')
      val.work = String(5 * (work / 100))
      var money = val.money.replace('%', '')
      val.money = String(5 * (money / 100))
    }
  }
}
</script>
<style lang="scss" scoped>
.detail {
  margin: 10px 0;
  > div {
    text-align: center;
    p {
      margin: 5px 0;
      font-size: 16px;
      &:first-child {
        font-weight: bold;
      }
    }
  }
}
.detailInfo {
  section {
    padding: 0 10px;
    margin: 10px 0;
    .title {
      h4 {
        font-size: 18px;
        color: #ffa92d;
        margin: 0 10px;
      }
      .line {
        width: 100px;
        border: 1px solid #f5ddd6;
        box-shadow: 3px 3px 5px #f5ddd6;
      }
    }
    .rate {
      margin: 5px 0 10px;
    }
    p {
      text-align: justify;
      text-indent: 30px;
      margin: 0 5px;
    }
  }
}
</style>

